package com.baomidou.ant.utils;
import java.text.DecimalFormat;
import java.util.DoubleSummaryStatistics;
import java.util.List;

public class MyMathUtils {
    //求标准差
    public static double standardDeviaction(List<Double> list){
        double sum = 0;
        DoubleSummaryStatistics statistics = list.stream().mapToDouble(Number::doubleValue).summaryStatistics();
        double meanValue = statistics.getAverage();                //平均数
        for(int i = 0;i < list.size();i++){
            sum += Math.pow(list.get(i)-meanValue, 2);
        }
        //只保留两位
        DecimalFormat df = new DecimalFormat("#.000");
        return Double.parseDouble(df.format(Math.sqrt(sum/list.size())));
    }
}
